package cn.com.pansky.util;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

import org.apache.commons.lang3.StringUtils;
public class DateUtil {
	
	/**
	 * 格式化当前系统时间（精确到秒）
	 * @return String
	 */
	public static String currentTime() {
		String strYMDHMSS = StringUtils.EMPTY;
		Date currentDateTime = new Date();
		SimpleDateFormat formatter = new SimpleDateFormat("yyyyMMddHHmmss");
		strYMDHMSS = formatter.format(currentDateTime);
		return strYMDHMSS;
	}
	
	/**
	 * 格式化当前系统时间（精确到毫秒）
	 * @return String
	 */
	public static String currentTimeToSS() {
		String strYMDHMSSS = StringUtils.EMPTY;
		Date currentDateTime = new Date();
		SimpleDateFormat formatter = new SimpleDateFormat("yyyyMMddHHmmssSSS");
		strYMDHMSSS = formatter.format(currentDateTime);
		return strYMDHMSSS;
	}
	
	/**
	 * 2016-09-16 11:40:00 日期格式
	 * @return
	 */
	public static String current19Time() {
		String strYMDHMSS = StringUtils.EMPTY;
		Date currentDateTime = new Date();
		SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); //2016-09-16 11:40:00
		strYMDHMSS = formatter.format(currentDateTime);
		return strYMDHMSS;
	}
	
	/**
	 * 获取当前时间推后n分钟的时间
	 * @param minute
	 * @return
	 */
	 public static String getTimeByMinute(int minute) {
        Calendar calendar = Calendar.getInstance();
        calendar.add(Calendar.MINUTE, minute);
        return new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(calendar.getTime());
	  }
	
	/**
	 * YYYY/MM/DD
	 * @return
	 */
	public static String current10Time() {
		String strYMDHMSS = StringUtils.EMPTY;
		Date currentDateTime = new Date();
		SimpleDateFormat formatter = new SimpleDateFormat("yyyy/MM/dd"); //2016-09-16
		strYMDHMSS = formatter.format(currentDateTime);
		return strYMDHMSS;
	}
	
	/**
	 * 
	 * @return
	 */
	public static String current8_Time() {
		String strYMDHMSS = StringUtils.EMPTY;
		Date currentDateTime = new Date();
		SimpleDateFormat formatter = new SimpleDateFormat("yyyyMMdd"); //2016-09-16
		strYMDHMSS = formatter.format(currentDateTime);
		return strYMDHMSS;
	}
	
	/**
	 * HH:MM:SS
	 * @return
	 */
	public static String current8Time() {
		String strYMDHMSS = StringUtils.EMPTY;
		Date currentDateTime = new Date();
		SimpleDateFormat formatter = new SimpleDateFormat("HH:mm:ss"); //
		strYMDHMSS = formatter.format(currentDateTime);
		return strYMDHMSS;
	}
	
	/**
	 * mmssSSS
	 */
	public static String current7Time() {
		String strYMDHMSS = StringUtils.EMPTY;
		Date currentDateTime = new Date();
		SimpleDateFormat formatter = new SimpleDateFormat("mmssSSS");
		strYMDHMSS = formatter.format(currentDateTime);
		return strYMDHMSS;
	}
	
	/**
	 * 获取当前日期的前一天
	 * @param args
	 */
	public static String getDateOfBankRefund(String format) {
		Calendar calendar = Calendar.getInstance();
		Date currentDateTime = new Date();
		calendar.setTime(currentDateTime);
		calendar.add(Calendar.DAY_OF_MONTH, -1);
		currentDateTime = calendar.getTime();
		return new SimpleDateFormat(format).format(currentDateTime);
	}
	
	public static void main(String[] args) {
		String d = "2016-11-08 12:02:48";
		try {
			Date date = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").parse(d);
			System.out.println(new SimpleDateFormat("yyyyMMdd").format(date));
			System.out.println(DateUtil.getTimeByMinute(30));
			System.out.println(DateUtil.current19Time());
			System.out.println();
		} catch (ParseException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
}
